﻿using System;

using HsTec.Mobile.Green.BLL;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;

public partial class PowerWarning_FixedRatioB_Manage : System.Web.UI.Page
{
    private FixedRatioBLL bll = new FixedRatioBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        if ((string)Session["Baimasoft_Pers_ID"] == null)
        {
            Response.Redirect("../Logon.aspx");
        }
        if (!this.IsPostBack)
        {
            try
            {
                Indicator.Text = Request.QueryString["sIndicator"].ToString();
            }
            catch
            {

            }
            GridView1.Attributes.Add("BorderColor", "LightSkyBlue");
            if (ViewState["sortDirection"] == null)
            {
                ViewState["sortDirection"] = " ASC";
            }
            if (ViewState["sortExpression"] == null)
            {
                ViewState["sortExpression"] = String.Empty;
            }
        }
    }

    private string GetSearchString()
    {
        string searchStr = "(1=1)";

        string sddlRegionid = sltArea.SelectedValue.ToString().Trim();
        if (sddlRegionid != "")
        {
            searchStr += " and Area_ID  ='" + sddlRegionid + "' ";
        }
        searchStr += " and Years  ='" + sltYear.Value.Trim() + "'";
        return searchStr;
    }
    private void BindGridViewData()
    {
        GridView1.DataSource = bll.GetFixedRatioList(sltYear.Value.Trim(), 1);
        GridView1.DataBind();
    }
    /// <summary>
    /// 查询标杆值的相关参数 并显示在GridView中 用户通过文本框输入标杆值信息
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BindGridViewData();
        //按各地市信息
        //5月单位业务量能耗占全年比例算法 = 2009年5月份/2009年全年单位业务量能耗
        //2009年全年单位业务量能耗 = 2009年全年单位业务量能耗*单位业务量能耗变化率
    }

    protected void btnAdd_ServerClick(object sender, EventArgs e)
    {
        Dictionary<string, string> dic = new Dictionary<string, string>();
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            HtmlInputText txtMonth = (HtmlInputText)(GridView1.Rows[i].Cells[6].FindControl("txtMonth"));
            dic.Add(GridView1.Rows[i].Cells[0].Text, txtMonth.Value);
        }
        int iBack = bll.SetFixedRatio(dic);
        if (iBack == 1)
        {
            Response.Write("<script language=javascript>alert('保存成功！');</script>");
        }
        else
        {
            Response.Write("<script language=javascript>alert('保存失败！');</script>");
        }
        BindGridViewData();
    }
    protected void btnExport_ServerClick(object sender, EventArgs e)
    {
    }
    protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            HtmlInputText txtMonth = (HtmlInputText)(e.Row.Cells[6].FindControl("txtMonth"));
            txtMonth.Value = e.Row.Cells[7].Text.Trim() == "0.00" ? "" : e.Row.Cells[7].Text.Trim().Replace("&nbsp;", "");
        }
    }
    protected void GridView1_Sorting(object sender, System.Web.UI.WebControls.GridViewSortEventArgs e)
    {

    }
    protected void GridView1_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
    {

    }
    protected void linkBtnGo_Click(object sender, EventArgs e)
    {

    }
}
